#pragma once

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Node
{
public:
	Node()
	{
		suffix = -1;
	}
	~Node()
	{
		for each (Node* n in Children)
		{
			delete n;
		}
	}

	Node(int number, int leftIndex, int rightIndex)
	{
		suffix = number;
		r = rightIndex;
		l = leftIndex;

		substr = pattern->substr(l, (r - l));
	}

	/*Node(int leftIndex)
	{
		r = pattern;
		l = leftIndex;

		substr = pattern->substr(l, (r - l));
	}*/

	Node* suffixLink;

	//The suffix number
	int suffix;

	//Left and right index of substring
	int l;
	int r;

	//Method for getting the string
	string getEdge(string* s){
		return s->substr(l, (r - l));
	}

	void InsertChild(int ownLenght,Node* child)
	{
		Node* branch = new Node(suffix,l + ownLenght, r);
		suffix = -1;
		branch->Children = vector<Node*>(Children);
		Children.clear();
		Children.push_back(branch);
		r = l + ownLenght;

		Children.push_back(child);
		substr = pattern->substr(l, (r - l));
	}

	char at(int index,string* pattern)
	{
		return pattern->at(index+l);
	}

	char front(string* pattern)
	{
		return pattern->at(l);
	}

	int length()
	{
		return r-l;
	}

	static string* pattern;

	vector<Node*> Children;

	string substr;
};

string* Node::pattern = NULL;

